import http from './interface.js'

import { Encrypt, Decrypt } from './decrypt.js'

http.config.baseUrl = 'http://150.158.149.222:8880/smart_home_interface'; //接口地址
//http.config.baseUrl = 'http://localhost:8880/smart_home_interface/'; //接口地址

http.interceptor.request = (config) => {
	
	
	config.data = {
		terminal: 'web',
		param_code: Encrypt(JSON.stringify(config.data)),
		param_data: Encrypt(JSON.stringify(config.data))
	}
	config.header = {
		'Authorization': 'Bearer f33287ad-b529-4794-8ce0-b67ea2c9f51d',
		'X-Access-Token': 'f33287ad-b529-4794-8ce0-b67ea2c9f51d'
	}
}

http.interceptor.response = (response) => {
	if (response.data && response.data.secert && response.data.data) {
		const encrypts = {}
		encrypts.encryptKey = response.data.secert
		encrypts.encryptData = response.data.data
		response.data.data = JSON.parse(Decrypt(encrypts))
	}
	return response;
}

export default http
